package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppDiscovers;
import com.ruoyi.system.service.IAppDiscoversService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发现管理Controller
 *
 * @author ruoyi
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/system/discovers")
public class AppDiscoversController extends BaseController {
    @Autowired
    private IAppDiscoversService appDiscoversService;

    /**
     * 查询发现管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:discovers:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppDiscovers appDiscovers) {
        startPage();
        List<AppDiscovers> list = appDiscoversService.selectAppDiscoversList(appDiscovers);
        for (AppDiscovers discovers : list) {
            if (discovers.getIsState() == 0L) {
                discovers.setEnable(true);
            } else {
                discovers.setEnable(false);
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出发现管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:discovers:export')")
    @Log(title = "发现管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppDiscovers appDiscovers) {
        List<AppDiscovers> list = appDiscoversService.selectAppDiscoversList(appDiscovers);
        ExcelUtil<AppDiscovers> util = new ExcelUtil<AppDiscovers>(AppDiscovers.class);
        util.exportExcel(response, list, "发现管理数据");
    }

    /**
     * 获取发现管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:discovers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appDiscoversService.selectAppDiscoversById(id));
    }

    /**
     * 新增发现管理
     */
    @PreAuthorize("@ss.hasPermi('system:discovers:add')")
    @Log(title = "发现管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppDiscovers appDiscovers) {
        appDiscovers.setIsState(0L);
        return toAjax(appDiscoversService.insertAppDiscovers(appDiscovers));
    }

    /**
     * 修改发现管理
     */
    @PreAuthorize("@ss.hasPermi('system:discovers:edit')")
    @Log(title = "发现管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppDiscovers appDiscovers) {
        return toAjax(appDiscoversService.updateAppDiscovers(appDiscovers));
    }

    /**
     * 删除发现管理
     */
    @PreAuthorize("@ss.hasPermi('system:discovers:remove')")
    @Log(title = "发现管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appDiscoversService.deleteAppDiscoversByIds(ids));
    }
}
